using System;
using Rsdn.Janus.Framework.Ipc;

namespace GoJanusCmd
{
	internal class SendCommand
	{
		public void Download(int topicId)
		{
			Send(string.Format("<download-topic><message-id>{0}</message-id><hint/></download-topic>",
				topicId));
		}

		public void Go(int topicId)
		{
			Send(string.Format("<goto-message><message-id>{0}</message-id></goto-message>", topicId));
		}

        public void GoURL(string link)
        {
            Send(string.Format(
                        "<goto-message><version>2</version><message-id>0</message-id><url>{0}</url></goto-message>",
                link));
        }

		private void Send(string msg)
		{
			using (var cpc = new ClientPipeConnection("JanusPipe"))
			{
				cpc.Connect();
				cpc.Write(msg);
			}
		}

	    public void DownloadUrl(string link, string linkText)
	    {
	        Send(
	            string.Format(
	                "<download-topic><version>2</version><message-id>0</message-id><url>{0}</url><hint>{1}</hint></download-topic>",
	                //MLHIDE
	                link,
	                linkText)
	            );
	    }
	}
}